package com.company.project.controller.wx.demo;

import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController()
@RequestMapping("/wxdemo/kefu")
public class WxKefuController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxMpService wxService;



    @RequestMapping("sendKfMsg")
    @ResponseBody
    public void SendKefuMessage() throws WxErrorException {
        WxMpKefuMessage message = new WxMpKefuMessage();
        message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
        message.setToUser("otxJT06yNLTNJTDQ6yu0ugHcoScg");
        message.setContent(
                "欢迎欢迎，热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");

        this.wxService.getKefuService().sendKefuMessage(message);

    }

    /**
     * 图文
     * @throws WxErrorException
     */
    @RequestMapping("sendKfMsg1")
    @ResponseBody
    public void SendKefuMessage1() throws WxErrorException {

        WxMpKefuMessage.WxArticle wxArticle = new WxMpKefuMessage.WxArticle();

        wxArticle.setTitle("hi how are you");
        wxArticle.setDescription("this is a demo demo");
        wxArticle.setPicUrl("https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1510307158&di=258b895c1f6840f2b2af3802f6493b66&src=http://imgsrc.baidu.com/imgad/pic/item/9213b07eca806538025ec1349ddda144ad348264.jpg");
        wxArticle.setUrl("https://jingyan.baidu.com/article/a3f121e4d3f752fc9052bb90.html");

        WxMpKefuMessage message = WxMpKefuMessage.NEWS().addArticle(wxArticle).toUser("otxJT06yNLTNJTDQ6yu0ugHcoScg").build();
        this.wxService.getKefuService().sendKefuMessage(message);

    }


}
